﻿@model BlogAppExt.Models.SearchVM

<h3>Search</h3>

<div class="row well">
    <form class="form-group" method="get">
        @if (Model.SearchString != "")
        {
            <input class="form-control" type="text" name="searchString" placeholder="Search..." value="@Model.SearchString" />
        }
        else
        {
            <input class="form-control" type="text" name="searchString" placeholder="Search..." />
        }
        <input class="form-control btn btn-info" type="submit" value="Search" />
    </form>
</div>

@if (Model.ResultsPosts.Count > 0)
{

    <div class="row well">
        <table class="table">
            @foreach (var result in Model.ResultsPosts)
            {
                if (@result.GetType().ToString() == "BlogAppExt.Models.BlogPost")
                {
                    <tr onclick="location.href='/Home/PostDetail/@result.Id'">
                        <td>@result.Title</td>
                        <td>@result.Text</td>
                    </tr>
                }
                else
                {
                    <tr onclick="location.href='/Home/PostDetail/@(((BlogAppExt.Models.CommentPost)result).ReplyToId)'">
                        <td>@result.Title</td>
                        <td>@result.Text</td>
                    </tr>
                }
            }

        </table>


    </div>
}
else
{
    <div class="row well">
        <div>No results...</div>
    </div>
}